﻿(function () {
    $namespace.register("Comkarl.Calipso.Controls");

    $global.Comkarl.Calipso.Controls.JsonClientProperty = $def({
        $constructor: function () {
            this.$_.shopItemList = null;
        },
        $members: {
            // Client property getter
            get_ShopItemList: function () {
                return this.$_.shopItemList;
            },

            // Client property setter
            set_ShopItemList: function (value) {
                this.$_.shopItemList = value;
            },

            // This control does not render HTML in client-side code
            render: function () {
                // Parsing client property JSON
                var shopItems = $.parseJSON(this.shopItemList);

                // Rendering as an ordered list...
                var orderedList = $("<ol />");

                for (var itemIndex in shopItems) {
                    $("<li />").append("Product name: " + shopItems[itemIndex].Name + "   Price: " + shopItems[itemIndex].Price)
                                 .appendTo(orderedList);
                }

                // Server control must give to which element will be appended the client-side code
                orderedList.appendTo($(this.parentElementSelector));
            },

            initialize: function () {
            }
        },
        $extends: $calipso$control
    });

    $calipso$manager.registerControl("JsonClientProperty", $global.Comkarl.Calipso.Controls.JsonClientProperty);
})();